class Solution {
public:
    long long pickGifts(vector<int>& gifts, int k) {
        priority_queue<long long>q;
        long long ans = 0;
        for (auto x : gifts) {
            q.push(x);
        }
        while (k--) {
            long long t = q.top();
            q.pop();
            long long x = sqrt(t);
            q.push(x);
        }
        while (q.size()) {
            ans += q.top();
            q.pop();
        }
        return ans;
    }
};